/*
 *  eliminar_nota_request.cpp
 *  Wilson
 *
 *  Created by Sebastian Orfino on 1/18/12.
 *  Copyright 2012 lbs3. All rights reserved.
 *
 */

#include "VCPlugInHeaders.h"
//sdk include
#include "ILayoutUIUtils.h"
#include "IDocument.h"
#include "ErrorUtils.h"

//project include
#include "csxs_facade.h"
#include "xmp_facade.h"
#include "pugixml.hpp"
#include "marcadores.h"

#include "eliminar_nota_request.h"
#include "eliminar_nota_response.h"

using namespace eventos;

void eliminar_nota_request::operator()(const csxs::event::Event * const eventParam)
{
	using namespace pugi;
	using namespace std;
	using namespace xmp;
	
	
	
	istringstream is(eventParam->data);
	xml_document xml_doc;
	bool16 res = kFalse;
	info_nota_t nota;
	if (xml_doc.load(is)) {
		
		xml_node payload_n = xml_doc.child("payload");
		
		nota.id = payload_n.child_value("id");
		if (nota.id.length())
		{
			IDocument * doc = Utils<ILayoutUIUtils>()->GetFrontDocument();
			if (!doc) return;
			wilson_metadata metadata(::GetUIDRef(doc));
			
			res = metadata.eliminar_nota(nota);
			if (res)
			{
				doc::marcadores marc(::GetUIDRef(doc));
				marc.eliminar(nota.id);
			}
		}
	}
	
	eliminar_nota_response evt;
	evt.nota() = nota;
	evt.resultado(res);
	
	wilson::despachar(evt);
}